home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dflt14.zip / MEMOPAD.C < prev    next >
Text File  |  1992-08-11  |  19KB  |  629 lines

  1. /* --------------- memopad.c ----------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. extern DBOX PrintSetup;
  6.  
  7. char DFlatApplication[] = "MemoPad";
  8.  
  9. static char Untitled[] = "Untitled";
  10. static int wndpos;
  11.  
  12. static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
  13. static void NewFile(WINDOW);
  14. static void SelectFile(WINDOW);
  15. static void PadWindow(WINDOW, char *);
  16. static void OpenPadWindow(WINDOW, char *);
  17. static void LoadFile(WINDOW);
  18. static void PrintPad(WINDOW);
  19. static void SaveFile(WINDOW, int);
  20. static void DeleteFile(WINDOW);
  21. static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
  22. static char *NameComponent(char *);
  23. static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
  24. static void FixTabMenu(void);
  25. #ifndef TURBOC
  26. void Calendar(WINDOW);
  27. #endif
  28. void BarChart(WINDOW);
  29. char **Argv;
  30.  
  31. #define CHARSLINE 80
  32. #define LINESPAGE 66
  33.  
  34. void main(int argc, char *argv[])
  35. {
  36.     WINDOW wnd;
  37.     if (!init_messages())
  38.         return;
  39.     Argv = argv;
  40.     if (!LoadConfig())
  41.         cfg.ScreenLines = SCREENHEIGHT;
  42.     wnd = CreateWindow(APPLICATION,
  43.                         "D-Flat MemoPad " VERSION,
  44.                         0, 0, -1, -1,
  45.                         &MainMenu,
  46.                         NULL,
  47.                         MemoPadProc,
  48.                         MOVEABLE  |
  49.                         SIZEABLE  |
  50.                         HASBORDER |
  51.                         MINMAXBOX |
  52.                         HASSTATUSBAR
  53.                         );
  54.  
  55.     LoadHelpFile();
  56.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  57.     while (argc > 1)    {
  58.         PadWindow(wnd, argv[1]);
  59.         --argc;
  60.         argv++;
  61.     }
  62.     while (dispatch_message())
  63.         ;
  64. }
  65. /* ------ open text files and put them into editboxes ----- */
  66. static void PadWindow(WINDOW wnd, char *FileName)
  67. {
  68.     int ax, criterr = 1;
  69.     struct ffblk ff;
  70.     char path[64];
  71.     char *cp;
  72.  
  73.     CreatePath(path, FileName, FALSE, FALSE);
  74.     cp = path+strlen(path);
  75.     CreatePath(path, FileName, TRUE, FALSE);
  76.     while (criterr == 1)    {
  77.         ax = findfirst(path, &ff, 0);
  78.         criterr = TestCriticalError();
  79.     }
  80.     while (ax == 0 && !criterr)    {
  81.         strcpy(cp, ff.ff_name);
  82.         OpenPadWindow(wnd, path);
  83.         ax = findnext(&ff);
  84.     }
  85. }
  86. /* ------- window processing module for the
  87.                     memopad application window ----- */
  88. static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  89. {
  90.     int rtn;
  91.     switch (msg)    {
  92.         case CREATE_WINDOW:
  93.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  94.             if (cfg.InsertMode)
  95.                 SetCommandToggle(&MainMenu, ID_INSERT);
  96.             if (cfg.WordWrap)
  97.                 SetCommandToggle(&MainMenu, ID_WRAP);
  98.             FixTabMenu();
  99.             return rtn;
  100.         case COMMAND:
  101.             switch ((int)p1)    {
  102.                 case ID_NEW:
  103.                     NewFile(wnd);
  104.                     return TRUE;
  105.                 case ID_OPEN:
  106.                     SelectFile(wnd);
  107.                     return TRUE;
  108.                 case ID_SAVE:
  109.                     SaveFile(inFocus, FALSE);
  110.                     return TRUE;
  111.                 case ID_SAVEAS:
  112.                     SaveFile(inFocus, TRUE);
  113.                     return TRUE;
  114.                 case ID_DELETEFILE:
  115.                     DeleteFile(inFocus);
  116.                     return TRUE;
  117.                 case ID_PRINTSETUP:
  118.                     DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
  119.                     return TRUE;
  120.                 case ID_PRINT:
  121.                     PrintPad(inFocus);
  122.                     return TRUE;
  123.                 case ID_EXIT:    
  124.                     if (!YesNoBox("Exit Memopad?"))
  125.                         return FALSE;
  126.                     break;
  127.                 case ID_WRAP:
  128.                     cfg.WordWrap = GetCommandToggle(&MainMenu, ID_WRAP);
  129.                     return TRUE;
  130.                 case ID_INSERT:
  131.                     cfg.InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  132.                     return TRUE;
  133.                 case ID_TAB2:
  134.                     cfg.Tabs = 2;
  135.                     FixTabMenu();
  136.                     return TRUE;
  137.                 case ID_TAB4:
  138.                     cfg.Tabs = 4;
  139.                     FixTabMenu();
  140.                     return TRUE;
  141.                 case ID_TAB6:
  142.                     cfg.Tabs = 6;                    
  143.                     FixTabMenu();
  144.                     return TRUE;
  145.                 case ID_TAB8:
  146.                     cfg.Tabs = 8;
  147.                     FixTabMenu();
  148.                     return TRUE;
  149.                 case ID_CALENDAR:
  150. #ifndef TURBOC
  151.                     Calendar(wnd);
  152. #endif
  153.                     return TRUE;
  154.                 case ID_BARCHART:
  155.                     BarChart(wnd);
  156.                     return TRUE;
  157.                 case ID_ABOUT:
  158.                     MessageBox(
  159.                          "About D-Flat and the MemoPad",
  160.                         "   ┌───────────────────────┐\n"
  161.                         "   │    ▄▄▄   ▄▄▄     ▄    │\n"
  162.                         "   │    █  █  █  █    █    │\n"
  163.                         "   │    █  █  █  █    █    │\n"
  164.                         "   │    █  █  █  █ █  █    │\n"
  165.                         "   │    ▀▀▀   ▀▀▀   ▀▀     │\n"
  166.                         "   └───────────────────────┘\n"
  167.                         "D-Flat implements the SAA/CUA\n"
  168.                         "interface in a public domain\n"
  169.                         "C language library originally\n"
  170.                         "published in Dr. Dobb's Journal\n"
  171.                         "    ------------------------ \n"
  172.                         "MemoPad is a multiple document\n"
  173.                         "editor that demonstrates D-Flat");
  174.                     return TRUE;
  175.                 default:
  176.                     break;
  177.             }
  178.             break;
  179.         default:
  180.             break;
  181.     }
  182.     return DefaultWndProc(wnd, msg, p1, p2);
  183. }
  184. /* --- The New command. Open an empty editor window --- */
  185. static void NewFile(WINDOW wnd)
  186. {
  187.     OpenPadWindow(wnd, Untitled);
  188. }
  189. /* --- The Open... command. Select a file  --- */
  190. static void SelectFile(WINDOW wnd)
  191. {
  192.     char FileName[64];
  193.     if (OpenFileDialogBox("*.PAD", FileName))    {
  194.         /* --- see if the document is already in a window --- */
  195.         WINDOW wnd1 = FirstWindow(wnd);
  196.         while (wnd1 != NULL)    {
  197.             if (stricmp(FileName, wnd1->extension) == 0)    {
  198.                 SendMessage(wnd1, SETFOCUS, TRUE, 0);
  199.                 SendMessage(wnd1, RESTORE, 0, 0);
  200.                 return;
  201.             }
  202.             wnd1 = NextWindow(wnd1);
  203.         }
  204.         OpenPadWindow(wnd, FileName);
  205.     }
  206. }
  207.  
  208. /* --- open a document window and load a file --- */
  209. static void OpenPadWindow(WINDOW wnd, char *FileName)
  210. {
  211.     static WINDOW wnd1 = NULL;
  212.     WINDOW wwnd;
  213.     struct stat sb;
  214.     char *Fname = FileName;
  215.     char *ermsg;
  216.     if (strcmp(FileName, Untitled))    {
  217.         if (stat(FileName, &sb))    {
  218.             ermsg = DFmalloc(strlen(FileName)+20);
  219.             strcpy(ermsg, "No such file as\n");
  220.             strcat(ermsg, FileName);
  221.             ErrorMessage(ermsg);
  222.             free(ermsg);
  223.             return;
  224.         }
  225.         Fname = NameComponent(FileName);
  226.     }
  227.     wwnd = WatchIcon();
  228.     wndpos += 2;
  229.     if (wndpos == 20)
  230.         wndpos = 2;
  231.     wnd1 = CreateWindow(EDITBOX,
  232.                 Fname,
  233.                 (wndpos-1)*2, wndpos, 10, 40,
  234.                 NULL, wnd, EditorProc,
  235.                 SHADOW     |
  236.                 MINMAXBOX  |
  237.                 CONTROLBOX |
  238.                 VSCROLLBAR |
  239.                 HSCROLLBAR |
  240.                 MOVEABLE   |
  241.                 HASBORDER  |
  242.                 SIZEABLE   |
  243.                 MULTILINE
  244.     );
  245.     if (strcmp(FileName, Untitled))    {
  246.         wnd1->extension = DFmalloc(strlen(FileName)+1);
  247.         strcpy(wnd1->extension, FileName);
  248.         LoadFile(wnd1);
  249.     }
  250.     SendMessage(wwnd, CLOSE_WINDOW, 0, 0);
  251.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  252. }
  253. /* --- Load the notepad file into the editor text buffer --- */
  254. static void LoadFile(WINDOW wnd)
  255. {
  256.     char *Buf = NULL;
  257.     int recptr = 0;
  258.     FILE *fp;
  259.  
  260.     if ((fp = fopen(wnd->extension, "rt")) != NULL)    {
  261.         while (!feof(fp))    {
  262.             handshake();
  263.             Buf = DFrealloc(Buf, recptr+150);
  264.             memset(Buf+recptr, 0, 150);
  265.             fgets(Buf+recptr, 150, fp);
  266.             recptr += strlen(Buf+recptr);
  267.         }
  268.         fclose(fp);
  269.         if (Buf != NULL)    {
  270.             SendMessage(wnd, SETTEXT, (PARAM) Buf, 0);
  271.             free(Buf);
  272.         }
  273.     }
  274. }
  275.  
  276. static int LineCtr;
  277. static int CharCtr;
  278.  
  279. /* ------- print a character -------- */
  280. static void PrintChar(FILE *prn, int c)
  281. {
  282.     int i;
  283.     if (c == '\n' || CharCtr == cfg.RightMargin)    {
  284.         fputs("\r\n", prn);
  285.         LineCtr++;
  286.         if (LineCtr == cfg.BottomMargin)    {
  287.             fputc('\f', prn);
  288.             for (i = 0; i < cfg.TopMargin; i++)
  289.                 fputc('\n', prn);
  290.             LineCtr = cfg.TopMargin;
  291.         }
  292.         CharCtr = 0;
  293.         if (c == '\n')
  294.             return;
  295.     }
  296.     if (CharCtr == 0)    {
  297.         for (i = 0; i < cfg.LeftMargin; i++)    {
  298.             fputc(' ', prn);
  299.             CharCtr++;
  300.         }
  301.     }
  302.     CharCtr++;
  303.     fputc(c, prn);
  304. }
  305.  
  306. /* --- print the current notepad --- */
  307. static void PrintPad(WINDOW wnd)
  308. {
  309.     if (*cfg.PrinterPort)    {
  310.         FILE *prn;
  311.         if ((prn = fopen(cfg.PrinterPort, "wt")) != NULL)    {
  312.             long percent;
  313.             BOOL KeepPrinting = TRUE;
  314.             unsigned char *text = GetText(wnd);
  315.             unsigned oldpct = 100, cct = 0, len = strlen(text);
  316.             WINDOW swnd = SliderBox(20, GetTitle(wnd), "Printing");
  317.             /* ------- print the notepad text --------- */
  318.             LineCtr = CharCtr = 0;
  319.             while (KeepPrinting && *text)    {
  320.                 PrintChar(prn, *text++);
  321.                 percent = ((long) ++cct * 100) / len;
  322.                 if ((int) percent != oldpct)    {
  323.                     oldpct = (int) percent;
  324.                     KeepPrinting = SendMessage(swnd, PAINT, 0, oldpct);
  325.                 }
  326.             }
  327.             if (KeepPrinting)
  328.                 /* ---- user did not cancel ---- */
  329.                 if (oldpct < 100)
  330.                     SendMessage(swnd, PAINT, 0, 100);
  331.                /* ------- follow with a form feed? --------- */
  332.                if (YesNoBox("Form Feed?"))
  333.                    fputc('\f', prn);
  334.             fclose(prn);
  335.         }
  336.         else
  337.             ErrorMessage("Cannot open printer file");
  338.     }
  339.     else
  340.         ErrorMessage("No printer selected");
  341. }
  342.  
  343. /* ---------- save a file to disk ------------ */
  344. static void SaveFile(WINDOW wnd, int Saveas)
  345. {
  346.     FILE *fp;
  347.     if (wnd->extension == NULL || Saveas)    {
  348.         char FileName[64];
  349.         if (SaveAsDialogBox(FileName))    {
  350.             if (wnd->extension != NULL)
  351.                 free(wnd->extension);
  352.             wnd->extension = DFmalloc(strlen(FileName)+1);
  353.             strcpy(wnd->extension, FileName);
  354.             AddTitle(wnd, NameComponent(FileName));
  355.             SendMessage(wnd, BORDER, 0, 0);
  356.         }
  357.         else
  358.             return;
  359.     }
  360.     if (wnd->extension != NULL)    {
  361.         WINDOW mwnd = MomentaryMessage("Saving the file");
  362.         if ((fp = fopen(wnd->extension, "wt")) != NULL)    {
  363.             fwrite(GetText(wnd), strlen(GetText(wnd)), 1, fp);
  364.             fclose(fp);
  365.             wnd->TextChanged = FALSE;
  366.         }
  367.         SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
  368.     }
  369. }
  370. /* -------- delete a file ------------ */
  371. static void DeleteFile(WINDOW wnd)
  372. {
  373.     if (wnd->extension != NULL)    {
  374.         if (strcmp(wnd->extension, Untitled))    {
  375.             char *fn = NameComponent(wnd->extension);
  376.             if (fn != NULL)    {
  377.                 char msg[30];
  378.                 sprintf(msg, "Delete %s?", fn);
  379.                 if (YesNoBox(msg))    {
  380.                     unlink(wnd->extension);
  381.                     SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  382.                 }
  383.             }
  384.         }
  385.     }
  386. }
  387. /* ------ display the row and column in the statusbar ------ */
  388. static void ShowPosition(WINDOW wnd)
  389. {
  390.     char status[30];
  391.     sprintf(status, "Line:%4d  Column: %2d",
  392.         wnd->CurrLine, wnd->CurrCol);
  393.     SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
  394. }
  395. /* ----- window processing module for the editboxes ----- */
  396. static int EditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  397. {
  398.     int rtn;
  399.     switch (msg)    {
  400.         case SETFOCUS:
  401.             if ((int)p1)    {
  402.                 wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  403.                 wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  404.             }
  405.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  406.             if ((int)p1 == FALSE)
  407.                 SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
  408.             else 
  409.                 ShowPosition(wnd);
  410.             return rtn;
  411.         case KEYBOARD_CURSOR:
  412.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  413.             ShowPosition(wnd);
  414.             return rtn;
  415.         case COMMAND:
  416.             switch ((int) p1)    {
  417.                 case ID_SEARCH:
  418.                     SearchText(wnd);
  419.                     return TRUE;
  420.                 case ID_REPLACE:
  421.                     ReplaceText(wnd);
  422.                     return TRUE;
  423.                 case ID_SEARCHNEXT:
  424.                     SearchNext(wnd);
  425.                     return TRUE;
  426.                 case ID_CUT:
  427.                     CopyToClipboard(wnd);
  428.                     SendMessage(wnd, COMMAND, ID_DELETETEXT, 0);
  429.                     SendMessage(wnd, PAINT, 0, 0);
  430.                     return TRUE;
  431.                 case ID_COPY:
  432.                     CopyToClipboard(wnd);
  433.                     ClearTextBlock(wnd);
  434.                     SendMessage(wnd, PAINT, 0, 0);
  435.                     return TRUE;
  436.                 case ID_PASTE:
  437.                     PasteFromClipboard(wnd);
  438.                     SendMessage(wnd, PAINT, 0, 0);
  439.                     return TRUE;
  440.                 case ID_DELETETEXT:
  441.                 case ID_CLEAR:
  442.                     rtn = DefaultWndProc(wnd, msg, p1, p2);
  443.                     SendMessage(wnd, PAINT, 0, 0);
  444.                     return rtn;
  445.                 case ID_HELP:
  446.                     DisplayHelp(wnd, "MEMOPADDOC");
  447.                     return TRUE;
  448.                 case ID_WRAP:
  449.                     SendMessage(GetParent(wnd), COMMAND, ID_WRAP, 0);
  450.                     wnd->WordWrapMode = cfg.WordWrap;
  451.                     return TRUE;
  452.                 case ID_INSERT:
  453.                     SendMessage(GetParent(wnd), COMMAND, ID_INSERT, 0);
  454.                     wnd->InsertMode = cfg.InsertMode;
  455.                     SendMessage(NULL, SHOW_CURSOR, wnd->InsertMode, 0);
  456.                     return TRUE;
  457.                 default:
  458.                     break;
  459.             }
  460.             break;
  461.         case CLOSE_WINDOW:
  462.             if (wnd->TextChanged)    {
  463.                 char *cp = DFmalloc(25+strlen(GetTitle(wnd)));
  464.                 SendMessage(wnd, SETFOCUS, TRUE, 0);
  465.                 strcpy(cp, GetTitle(wnd));
  466.                 strcat(cp, "\nText changed. Save it?");
  467.                 if (YesNoBox(cp))
  468.                     SendMessage(GetParent(wnd),
  469.                         COMMAND, ID_SAVE, 0);
  470.                 free(cp);
  471.             }
  472.             wndpos = 0;
  473.             if (wnd->extension != NULL)    {
  474.                 free(wnd->extension);
  475.                 wnd->extension = NULL;
  476.             }
  477.             break;
  478.         default:
  479.             break;
  480.     }
  481.     return DefaultWndProc(wnd, msg, p1, p2);
  482. }
  483. /* -- point to the name component of a file specification -- */
  484. static char *NameComponent(char *FileName)
  485. {
  486.     char *Fname;
  487.     if ((Fname = strrchr(FileName, '\\')) == NULL)
  488.         if ((Fname = strrchr(FileName, ':')) == NULL)
  489.             Fname = FileName-1;
  490.     return Fname + 1;
  491. }
  492.  
  493. static char *ports[] = {
  494.     "Lpt1",    "Lpt2",    "Lpt3",
  495.     "Com1",    "Com2",    "Com3",    "Com4",
  496.       NULL
  497. };
  498.  
  499. static int PrintSetupProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  500. {
  501.     int rtn, i = 0, mar;
  502.     char marg[10];
  503.     WINDOW cwnd;
  504.     switch (msg)    {
  505.         case CREATE_WINDOW:
  506.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  507.             PutItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort);
  508.             while (ports[i] != NULL)
  509.                 PutComboListText(wnd, ID_PRINTERPORT, ports[i++]);
  510.             for (mar = CHARSLINE; mar >= 0; --mar)    {
  511.                 sprintf(marg, "%3d", mar);
  512.                 PutItemText(wnd, ID_LEFTMARGIN, marg);
  513.                 PutItemText(wnd, ID_RIGHTMARGIN, marg);
  514.             }
  515.             for (mar = LINESPAGE; mar >= 0; --mar)    {
  516.                 sprintf(marg, "%3d", mar);
  517.                 PutItemText(wnd, ID_TOPMARGIN, marg);
  518.                 PutItemText(wnd, ID_BOTTOMMARGIN, marg);
  519.             }
  520.             cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  521.             SendMessage(cwnd, LB_SETSELECTION,
  522.                 CHARSLINE-cfg.LeftMargin, 0);
  523.             cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  524.             SendMessage(cwnd, LB_SETSELECTION,
  525.                 CHARSLINE-cfg.RightMargin, 0);
  526.             cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  527.             SendMessage(cwnd, LB_SETSELECTION,
  528.                 LINESPAGE-cfg.TopMargin, 0);
  529.             cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  530.             SendMessage(cwnd, LB_SETSELECTION,
  531.                 LINESPAGE-cfg.BottomMargin, 0);
  532.             return rtn;
  533.         case COMMAND:
  534.             if ((int) p1 == ID_OK && (int) p2 == 0)    {
  535.                 GetItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort, 4);
  536.                 cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  537.                 cfg.LeftMargin = CHARSLINE -
  538.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  539.                 cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  540.                 cfg.RightMargin = CHARSLINE -
  541.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  542.                 cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  543.                 cfg.TopMargin = LINESPAGE -
  544.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  545.                 cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  546.                 cfg.BottomMargin = LINESPAGE -
  547.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  548.             }
  549.             break;
  550.         default:
  551.             break;
  552.     }
  553.     return DefaultWndProc(wnd, msg, p1, p2);
  554. }
  555.  
  556. static void FixTabMenu(void)
  557. {
  558.     char *cp = GetCommandText(&MainMenu, ID_TABS);
  559.     if (cp != NULL)    {
  560.         cp = strchr(cp, '(');
  561.         if (cp != NULL)    {
  562.             *(cp+1) = cfg.Tabs + '0';
  563.             if (GetClass(inFocus) == POPDOWNMENU)
  564.                 SendMessage(inFocus, PAINT, 0, 0);
  565.         }
  566.     }
  567. }
  568.  
  569. void PrepFileMenu(void *w, struct Menu *mnu)
  570. {
  571.     WINDOW wnd = w;
  572.     DeactivateCommand(&MainMenu, ID_SAVE);
  573.     DeactivateCommand(&MainMenu, ID_SAVEAS);
  574.     DeactivateCommand(&MainMenu, ID_DELETEFILE);
  575.     DeactivateCommand(&MainMenu, ID_PRINT);
  576.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  577.         if (isMultiLine(wnd))    {
  578.             ActivateCommand(&MainMenu, ID_SAVE);
  579.             ActivateCommand(&MainMenu, ID_SAVEAS);
  580.             ActivateCommand(&MainMenu, ID_DELETEFILE);
  581.             ActivateCommand(&MainMenu, ID_PRINT);
  582.         }
  583.     }
  584. }
  585.  
  586. void PrepSearchMenu(void *w, struct Menu *mnu)
  587. {
  588.     WINDOW wnd = w;
  589.     DeactivateCommand(&MainMenu, ID_SEARCH);
  590.     DeactivateCommand(&MainMenu, ID_REPLACE);
  591.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  592.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  593.         if (isMultiLine(wnd))    {
  594.             ActivateCommand(&MainMenu, ID_SEARCH);
  595.             ActivateCommand(&MainMenu, ID_REPLACE);
  596.             ActivateCommand(&MainMenu, ID_SEARCHNEXT);
  597.         }
  598.     }
  599. }
  600.  
  601. void PrepEditMenu(void *w, struct Menu *mnu)
  602. {
  603.     WINDOW wnd = w;
  604.     DeactivateCommand(&MainMenu, ID_CUT);
  605.     DeactivateCommand(&MainMenu, ID_COPY);
  606.     DeactivateCommand(&MainMenu, ID_CLEAR);
  607.     DeactivateCommand(&MainMenu, ID_DELETETEXT);
  608.     DeactivateCommand(&MainMenu, ID_PARAGRAPH);
  609.     DeactivateCommand(&MainMenu, ID_PASTE);
  610.     DeactivateCommand(&MainMenu, ID_UNDO);
  611.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  612.         if (isMultiLine(wnd))    {
  613.             if (TextBlockMarked(wnd))    {
  614.                 ActivateCommand(&MainMenu, ID_CUT);
  615.                 ActivateCommand(&MainMenu, ID_COPY);
  616.                 ActivateCommand(&MainMenu, ID_CLEAR);
  617.                 ActivateCommand(&MainMenu, ID_DELETETEXT);
  618.             }
  619.             ActivateCommand(&MainMenu, ID_PARAGRAPH);
  620.             if (!TestAttribute(wnd, READONLY) &&
  621.                         Clipboard != NULL)
  622.                 ActivateCommand(&MainMenu, ID_PASTE);
  623.             if (wnd->DeletedText != NULL)
  624.                 ActivateCommand(&MainMenu, ID_UNDO);
  625.         }
  626.     }
  627. }
  628.  
  629.